package tt.lab.pmbok.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

@Entity(name="area")
public class Area {
	private int id;
	private String name;
	
	
	private Set<PmbokProcess> processes;
	private List<PmbokProcess> sortedProcesses;
	
	@Id
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@OneToMany
	@JoinColumn(name="area_id")
	public Set<PmbokProcess> getProcesses() {
		return processes;
	}
	public void setProcesses(Set<PmbokProcess> processes) {
		this.processes = processes;
		
		sortedProcesses = new ArrayList<PmbokProcess>();
		for (PmbokProcess process : getProcesses()) {
			
				sortedProcesses.add(process);
		}
		Collections.sort(sortedProcesses);
			
	}
	
	@Transient
	public List<PmbokProcess> getSortedProcesses() {
		return sortedProcesses;
	}
	
}
